package IO;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class SingleDemo {
    public static void main(String[] args) throws Exception {
        List<String>list=new ArrayList<>();
        try (Reader re=new FileReader("day10-file_io/src/File6.txt");
             BufferedReader br=new BufferedReader(re);
             Writer we=new FileWriter("day10-file_io/src/File7.txt");
             BufferedWriter bw=new BufferedWriter(we);
             ){
            String s;
            while((s=br.readLine())!=null) {
                list.add(s);
            }
            sortline(list);
//            String line;
            for(String line:list){
                bw.write(line);
                bw.newLine();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //可简化为：Collections.sort(list,(s1,s2)->s1.charAt(0)-s2.charAt(0));
    public static void sortline(List<String> list) {
        Collections.sort(list, (s1, s2) -> s1.charAt(0) - s2.charAt(0));
    }
}


